import 'package:app/pages/office_supplies_modules/all_office_supplies_module/all_office_supplies_page.dart';
import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:get/get.dart';

import '../../../router/app_pages.dart';
import 'package:intl/intl.dart' as Datee;

class CreateOfficeController extends GetxController{


  List<String> userIdName = ['请选择使用人'];
  List<int>? userId;

  // var userName = '请选择使用人';
  // var userId;

  var goodsName = '申请的用品';
  var goodsId;

  var number = 1;

  var startTime = '请选择开始时间';
  var placeKeepController = TextEditingController();

  requestDataWithCreate()async{

    var params = {
      'user_id':userId![0],
      'office_use_id':0,
      'date':startTime,
      'place_keep':placeKeepController.text,
      'goods_id':goodsId,
      'number':number,
    };

    var json = await DioManager().kkRequest(Address.officeCreate,bodyParams:params);
    if(json['errmsg'] == 'ok'){
      Get.back(result: 'refresh');
    }
    BotToast.showText(text: json['message']);

  }

  tapClickUser()async{
    var params = {
      'isMultiple':false,
      'personnelIdArr':userId,
      // 'personnelNameArr':userIdName
    };

    var data = await Get.toNamed(AppRoutes.personnel,arguments: params);
    print('data======${data}');
    if(data != null){
      print(data);
      userIdName.remove('请选择使用人');
      userIdName = data['personnelNameArr'];
      userId = data['personnelIdArr'];
      update();
    }

    // var params = {
    //   'isMultiple':false,
    //   'personnelIdArr':userId,
    //   // 'personnelNameArr':userIdName
    // };
    //
    // var data = await Get.toNamed(AppRoutes.personnel,arguments: params);
    //
    // if(data != null){
    //   print(data);
    //   userName = data['personnelNameArr'][0];
    //   userId = data['personnelIdArr'][0];
    // }
    // update();
  }

  ///
  taoClickGoods()async{
    var data = await Get.to(AllOfficeSuppliesPage());
    if(data != null){
      goodsName = data['name'];
      goodsId = data['id'];
    }
    update();
  }
  ///
  tapClickStartTime()async{
    DatePicker.showDatePicker(Get.context!,
        showTitleActions: true,
        minTime: DateTime(1990, 1, 1),
        maxTime: DateTime(2025, 12, 12), onChanged: (date) {

        }, onConfirm: (date) {
          print('${date.year}-${date.month}-${date.day}');

          var timeFormat = Datee.DateFormat("yyyy-MM-dd");
          var timeStr = timeFormat.format(date);

          startTime = timeStr;

          // controller.
          // requestDataWithUpdataInfo(alias_name: controller.editingController.text,
          //     sex: '女',birthday: '${date.year}-${date.month}-${date.day}');
          print('confirm $date');
          update();
        }, currentTime: DateTime.now(), locale: LocaleType.zh);

  }
  
}